#!/bin/bash

die()
{
  echo "$@" >&2
  exit 1
}

echo "  **info** This script copies the vxref plugin files to your ~/.vim directory."
echo "           Every user that wants to run vxref must install vxref into their "
echo "           home folder by running this script"


mkdir -p ~/.vim/vxref || die "  **error** creating ~/.vim/vxref" 
mkdir -p ~/.vim/plugin || die "  **error** creating ~/.vim/plugin"
cp bin/{vxrefserver,startserver.sh,cleanup.sh,meta.sh,pipeserver}  plugin/vxref.vim ~/.vim/vxref || die "  **error** copying bin files to ~/.vim/vxref"
ln -sf ~/.vim/vxref/vxref.vim ~/.vim/plugin/vxref.vim  || die "  **error** linking vim script "

which xref &> /dev/null
if [[ $? -gt 0 ]]
then
  echo "  **error** no binary 'xref' found in path, please see online wiki documentation on how to install xref "
  echo "            vxref will not work at all without xref! duh :) "
  exit 1
fi

echo -en '  **\E[32m'"successful install\033[0m**\n"
